package com.woniuxy.controller;


import com.woniuxy.demo.Result;
import com.woniuxy.dto.GoodsAppraisalHistoryDto;
import com.woniuxy.dto.commonDto.BaseDto;
import com.woniuxy.entity.GoodsAppraisalHistory;
import com.woniuxy.enums.CodeEnum;
import com.woniuxy.exception.AppraisalException;
import com.woniuxy.param.GoodsAppraisalHistoryParam;
import com.woniuxy.param.GoodsAppraisalParam;
import com.woniuxy.service.GoodsAppraisalHistoryService;
import com.woniuxy.util.ValidatedUtil;
import com.woniuxy.util.WoniuBeanUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 评估鉴定里面的历史鉴定记录 前端控制器
 * </p>
 *
 * @author zcx,ftl,gr,rhs
 * @since 2021-12-31
 */
@RestController
@RequestMapping("/goods-appraisal-history")
@Api(tags = "历史鉴定记录的接口")
public class GoodsAppraisalHistoryController {

    @Resource
    private GoodsAppraisalHistoryService goodsAppraisalHistoryService;


    @GetMapping("/getGoodsAppraisal")
    @ApiOperation("查询所有历史鉴定记录")
    public Result getGoodsAppraisal(){

        return Result.newInstance().setCode(200).setMsg("查询成功")
                .setData(goodsAppraisalHistoryService.list());
    }

    @ApiOperation("分页获取历史鉴定记录")
    @PostMapping("/getdistributor")
    public Result getGoodsAppraisalHistory(@RequestBody GoodsAppraisalHistoryParam gah) {
        BaseDto<GoodsAppraisalHistoryDto> goodsAppraisalHistorys = goodsAppraisalHistoryService.getAppraisalHistory(gah);
        return Result.newInstance().setCode(200).setMsg("查询成功").setData(goodsAppraisalHistorys);
    }

    @ApiOperation("添加鉴定记录信息")
    @PostMapping("/addAppraisal")
    public Result addAppraisal(@RequestBody  GoodsAppraisalParam gap) {
        //参数验证

        if (goodsAppraisalHistoryService.addGoodsAppraisal(gap)) {
            GoodsAppraisalHistoryDto goodsAppraisalHistoryDto = WoniuBeanUtils.copyObject(gap, GoodsAppraisalHistoryDto.class);
            return new Result().setCode(200).setMsg("添加成功").setData(goodsAppraisalHistoryDto);
        }
        throw new AppraisalException(CodeEnum.APPRAISAL_SAVE_FAIL_5.getMessage()
                , CodeEnum.APPRAISAL_SAVE_FAIL_5.getCode());
    }
}

